package com.kitty.syn;
import com.kitty.core.Core;
import java.lang.reflect.InvocationTargetException;
import java.util.*;

import org.springframework.util.MethodInvoker;
import org.springframework.beans.factory.config.MethodInvokingFactoryBean;
import net.sf.json.*;
public class Main {

	 
	public static void main(String[] args) throws Exception {
		//static method invoke,
		MethodInvoker methodInvoker = new MethodInvoker();
		methodInvoker.setStaticMethod("com.kitty.syn.Main.jsonTest");
		methodInvoker.setTargetClass(Main.class);
		methodInvoker.prepare();
		methodInvoker.invoke();
		
		//common method invoke,
		MethodInvoker commonMethod = new MethodInvoker();
		commonMethod.setTargetObject(new Main());
		commonMethod.setArguments(new Object[]{"first arg!"});
		commonMethod.setTargetMethod("commonMethod");
		commonMethod.prepare();
		commonMethod.invoke();
		
		MethodInvokingFactoryBean mifb = new MethodInvokingFactoryBean();
		mifb.setTargetObject(new Core());
		mifb.setSingleton(true);
		mifb.setTargetMethod("play");
		mifb.prepare();
		mifb.invoke();
	}
	
	
	private void commonMethod(String arg) {
		System.out.println("AAA:" + arg);
	}
	
	private static void jsonTest() {
		List<String> list = Arrays.asList("one","two","three");
		
		String[] array = new String[]{"fourth","fifth","sixth"};
		
		EntityObject eo = new EntityObject();
		eo.setIndex(0);
		eo.setName("entity");
		eo.setPassword("password");
		eo.getValueObject().setEmail("email");
		eo.getValueObject().setId(23);
		
		Map<String,String> map = new HashMap<String,String>();
		map.put("first", "firstValue");
		map.put("second", "secondValue");
		map.put("third", "thirdValue");
		JSONArray ja = JSONArray.fromObject(eo);
		System.out.println(ja);
	}
	
	private static void syn() {
		System.out.println(System.getProperty("user.home"));
		final ResourcePool pool = new ResourcePool(new ResourceFactoryImpl(), 2);
		try {
			Object o = pool.getResource();
			final Object o2 = pool.getResource();
			
			Thread t = new Thread(new Runnable() {
				public void run() {
					try {
						System.out.println("开始休眠--");
						Thread.sleep(5000);
						System.out.println("结束休眠--");
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					pool.returnResource(o2);
				}
			});
			t.start();
			Object o3 = pool.getResource();
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
	private static void play() {
		List<String> list = Collections.synchronizedList(new ArrayList<String>());
		//List<String> list = new ArrayList<String>();
		
		FirstRunnable firstRunnable = new FirstRunnable(list,5);
		
		SecondRunnable secondRunnable = new SecondRunnable(list,5,firstRunnable);
		
		//secondThread.join();
		
		firstRunnable.setRunnable(secondRunnable);
		
		Thread secondThread = new Thread(secondRunnable);
		secondThread.start();
		Thread firstThread = new Thread(firstRunnable);
		firstThread.start();
	}

}
/* 
 * 类库代码，框架代码，程序代码，
 * 组件： 一组接口,一组抽象类,一组具体类,一组异常类,一组帮助类,
 * 转发、委托、回调, 构造方法,属性方法,普通方法,从缓存、文件、数据库查询,
 * 对象:对象是什么:对一个事物的抽象描述;
 * 		对象的组成部分:对象由哪些部分组成,对象又是哪些事物的组成部分;
 *      对象的特征:标识符、状态、行为；抽象、封装、模块化、层次化、类型、并发、持久性;
 *      对象的生命周期:实例化(new关键字,clone(),反序列化,反射),初始化,服务,销毁;
 *      对象的空间、时间维度;  
 *      对象的边界、所处的场景,
 *      对象之间的关系:依赖、关联、组合、复合、继承;
 *      对象的物理含义、逻辑含义;
 * 类、类型:
 * 
 * 做为值出现,还是做为类型出现,
 * 类型字段与类型之间的关系,
 * 
 * Entity Object,Value Object,Factory,Service,Repository,
 * 实体对象的生命周期,边界,
 * 新建，重建，
 * 
 * 
前提条件，
执行过程，
后置条件，
异常处理，

目标明确，步骤清晰，

相同、相似、不同
抽象，封装，继承，多态，
转发，委托，回调，

业务层(概念)，技术层(实现)，

OOP,DI,AOP(完备的切入点理论,被通知对象对通知的一无所知),
 * 
 *  
 */

 